package main

import (
	"fmt"
)

// 定义学生结构体
type Studentmap struct {
	ID   int
	Name string
	Age  int
}

// Map函数：将一个学生切片转换为另一个学生切片
func mapStudents(students []Student, transform func(Student) Student) []Student {
	result := make([]Student, len(students))
	for i, s := range students {
		result[i] = transform(s)
	}
	return result
}

func main() {
	// 创建一些学生数据
	students := []Student{
		{ID: 1, Name: "张三", Age: 20},
		{ID: 2, Name: "李四", Age: 22},
		{ID: 3, Name: "王五", Age: 21},
	}

	// 使用map函数增加所有学生的年龄1岁
	updatedStudents := mapStudents(students, func(s Student) Student {
		s.Age += 1
		return s
	})

	// 输出更新后的学生信息
	for _, s := range updatedStudents {
		fmt.Printf("ID: %d, 姓名: %s, 年龄: %d\n", s.ID, s.Name, s.Age)
	}
}
